package com.qf.blog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.blog.commons.utils.ConvertUtils;
import com.qf.blog.dto.UserDTO;
import com.qf.blog.entity.User;
import com.qf.blog.mapper.UserMapper;
import com.qf.blog.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class SysUserServiceImpl extends ServiceImpl<UserMapper, User> implements ISysUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<UserDTO> queryAll() {
        List<User> list = super.list();
        return ConvertUtils.sourceToTarget(list, UserDTO.class);
    }

    @Override
    public boolean add(UserDTO userDTO) {
        User user = ConvertUtils.sourceToTarget(userDTO, User.class);
        return super.save(user);
    }

    @Override
    public boolean updateById(UserDTO userDTO) {
        User user = ConvertUtils.sourceToTarget(userDTO, User.class);
        return super.updateById(user);
    }
}
